# # 输入1 表示愿意学习py、输入2 表示不愿意、default 表示不知道
# is_study = input("输入一个数字 : ")
# is_study = int(is_study)
# if is_study == 1:
#     print("愿意学习")
#     print("sasaas")
#     print("sasasa")
# elif is_study == 2:
#     print("不愿意")
#     print("sasaas")
#     print("sasasa")
# else:
#     print("不知道")
#     print("sasaas")
#     print("sasasa")
# 输入一个整数，判定他是否为奇数
# num = int(input("请输入一个整数 : "))
# if num % 2 == 0:
#     print(f"{num}是一个偶数")
# else:
#     print(f"{num}是一个奇数")
# while 1:
#     try:
#         num = int(input("请输入一个数 : "))
#         break
#     except ValueError:
#         print("输入错误请重新输入")
#
# if num < 0:
#     print(f"{num}是一个负数")
# elif num == 0:
#     print(f"{num} = 0")
# else:
#     print(f"{num}是一个正数")
# 判定一个年份是否为闰年
# while 1:
#     while 1:
#         try:
#             num = int(input("请输入一个年份 : "))
#             break
#         except ValueError:
#             print("输入错误，请重新输入 ")
#     if (num % 4 == 0 and num % 100 != 0) or num % 400 == 0:
#         print(f"{num}是闰年")
#     else:
#         print(f"{num}不是闰年")
# 打印1-10的正数
# num = 1
# while num <= 10:
#     print(num)
#     num += 1
# 计算1-100的和
# num = 1
# sum = 0
# while num <= 100:
#     sum += num
#     num += 1
# print(f"1-100的和为{sum}")
# 5的阶乘
# num = 1
# sum = 1
# while num <= 5:
#     sum *= num
#     num += 1
# print(f"sum = {sum}")
# 求 1！+ 2！+ 3！+ 4！+ 5！
# 记录每个阶乘
# sum = 1
# # 数字
# num = 1
# # 阶乘和
# total = 0
# while num <= 5:
#     sum *= num
#     total += sum
#     num += 1
# print(f"total = {total}")
# 1 + 。。。 + 100
# sum_ = 0
# for i in range(1, 101):
#     sum_ += i
# print(f"sum = {sum_}")
# 给定若干个数字，来求平均值
# sum_num = 0
# count = 0
# while True:
#     num = input("请输入数字, 输入结束，输入OK : ")
#     if num != 'OK':
#
#         try:
#             float(num)
#         except ValueError:
#             print("输入错误，请重新输入")
#             continue
#
#         sum_num += float(num)
#         count += 1
#
#     else:
#         break
# print(f"平均值 = {sum_num / count}")
# def my_sum():
#     total = 0
#     for i in range(beg, end + 1):
#         total += i
#     return total
#
#
# print(my_sum(1))
# print(my_sum(1))
# for i in range(1, 5):
#     c = 3
# print(f"i = {i}")
# 使用递归的方法，完成1-100的累加
# def add_sum(num, debug=False, info=False, err=False):
#     if num == 0:
#         return 0
#     return add_sum(num - 1) + num
#
#
# print(add_sum(100, info=True))
#
# arr1 = [1, 2, 3, 4, 5]
# arr2 = list([123, 12, 1])
# arr1[4] = 50
# arr1[-2] = 40
#
# print(arr1)
# print(arr2)
# arr = [1, 2, 3, 4, 1, 2, 3, 4]
# arr.remove(1)
# print(arr)
# hash_1 = {"name": "王有东", "性别": "男", "年龄": "20"}
# print(hash_1)
# l = [1, 2, 3, 4]
# f = open()
# import datetime
# begin = datetime.datetime(year=2022, month=6, day=29)
# end = datetime.datetime(year=2024, month=3, day=3)
# print(end - begin)
# def reverse_words(s: str):
#     arr = s.split(' ')
#     arr.reverse()
#     return ' '.join(arr)
#
#
# print(reverse_words("hello my wife!"))
# def rotateString(s: str, goal: str):
#     if len(s) != len(goal):
#         return False
#     return goal in (s + s)
#
#
# print(rotateString("abcde", "bcdea"))
# print(rotateString("abcde", "bcdss"))
# def Is_front_str(arr_str: list, s: str):
#     count = 0
#     for i in arr_str:
#         if s.startswith(i):
#             count += 1
#     return count
#
#
# print(Is_front_str(["a", "a", "a", "ab", "bc", "abc"], "abc"))

# print('a', 'b', sep='-', end=';')
# def reverse_str(s: str):
#     return s[::-1]
#
#
# print(reverse_str("a,b,c,d"))
# Python 的面向对象
# class Student(object):
#     def __init__(self, name, sex, id):
#         self.__name = name
#         self.__sex = sex
#         self.__id = id
#
#     # 测试成员
#     def print_student(self):
#         # print(self.name, self.sex, self.id)
#         print("%s:%s:%s" % (self.__name, self.__sex, self.__id))
#
#     def set_name(self, name):
#         self.__name = name
#
#     def set_id(self, id):
#         self.__id = id
#
#
# s1 = Student("王有东", "男", "10")
# s1.print_student()
# s1.set_name("wyd")
# s1.print_student()
# class Animal(object):
#     def __init__(self, name):
#         self.name = name
#
#     def run(self):
#         print("Animal is running")
#
#     def Fun(self, id="666"):
#         print(id)
#
#
# class Dog(Animal):
#     def run(self):
#         print(f"{self.name} is running")
#
#     def Fun(self, id="777"):
#         print(id)
#
#
# class Cat(Animal):
#     def run(self):
#         print(f"{self.name} is running")
#
#
# dog = Dog("dog")
# dog.Fun()
# cat = Cat("cat")
# cat.run()
# print(dir(print))
# class Student(object):
#     __name = "ll"
# class Student(object):
#     pass
#
#
# s = Student()
# s.name = "wyd"
# s.sum = lambda x, y: x + y
# print(s.sum(1, 2))
# class Animal(object):
#     __slots__ = ('kindof', 'sex')
#
#
# class Cat(Animal):
#     pass
#
#
# # a1 = Animal()
# # a1.kindof = "cat"
# # a1.sex = "母"
# # a1.hh = "SA"
# # print(a1.kindof, a1.sex, a1.hh)
# c = Cat()
# c.kindof = "cat"
# c.new = "sa"
# print(c.kindof, c.new)
# class Student(object):
#     @property
#     def score(self):
#         return self.value
#
#     @score.setter
#     def score(self, value):
#         if not isinstance(value, int):
#             raise print("输入的类型不是整数")
#         if value < 0 or value > 100:
#             raise print("分数必须是0～100的整数")
#         self.value = value
#
#
# s = Student()
# s.score = 100
# print(s.score)
# a = int(input("请输入一个数字 : "))
# print(f"{a} ^ 5 = {a ** 5}")
"""
 此处为注释，你能看到我吗？？？
 # print("hello 'sasas' sasa")
"""


# import sys
# import time

# a = 10
# print(a)
# a = "hello"
# print(a)
# a = True
# print(a)
# a = (1, 2, 3)
# print(a)
# a = [1, 2, 3]
# print(a)
# a = {"hello": 1, "wyd": 21}
# print(a)
# a: int = "SAs"
# print(type(a))
# print("2024", "6", "10", sep="-", end=";", flush=True)
# print()
# time.sleep(10)/
# for i in range(1, 10):
#     print(i)
# time.sleep(10)
# class Person(object):
#     def __init__(self, name: str, sex: str, id: int):
#         self.__name = name
#         self.__sex = sex
#         self.__id = id
#
#     def print(self):
#         print(self.__name, self.__sex, self.__id, sep="-", end=";")
#
#
# class Student(Person):
#     def print(self):
#         print("Student")
#
#
# s = Student("wyd", "man", 22)
# s.print()
import heapq


# class Solution(object):
#     def halveArray(self, nums) -> int:
#         # 都变成负数，以便模拟大根堆
#         for i in nums:
#             nums[i] *= -1
#         # 将list变成堆
#         heapq.heapify(nums)
#         # 求和
#         sum_nums = sum(nums)
#         sum_oper = sum_nums
#         count = 0
#         # 每次拿堆的首部元素计算
#         while True:
#             if sum_oper >= sum_nums / 2:
#                 return count
#             tmp = nums[0] / 2
#             sum_oper -= tmp
#             count += 1
#             heapq.heappushpop(nums, tmp)
# class Solution(object):
#     def halveArray(self, nums):
#         # 都变成负数，以便模拟大根堆
#         for i in nums:
#             i *= -1
#         # 将list变成堆
#         heapq.heapify(nums)
#         # 求和
#         sum_nums = sum(nums)
#         sum_oper = sum_nums
#         count = 0
#         # 每次拿堆的首部元素计算
#         while sum_oper >= sum_nums / 2:
#             tmp = nums[0] / 2
#             sum_oper -= tmp
#             count += 1
#             heapq.heappushpop(nums, tmp)
#         return count
#
#
# a = Solution().halveArray([5, 19, 8, 1])

# nums = [1,2,3,4]
# for i in nums:
#     i += 1
# print(nums)
# class Solution(object):
#     def halveArray(self, n):
#         # 都变成负数，以便模拟大根堆
#         nums = []
#         heapq.heapify(nums)
#         for i in n:
#             heapq.heappush(nums, -i)
#
#         # 求和
#         sum_nums = sum(nums)
#         sum_oper = sum_nums
#         count = 0
#         # 每次拿堆的首部元素计算
#         while sum_oper < sum_nums / 2:
#             tmp = nums[0] / 2
#             sum_oper -= tmp
#             count += 1
#             heapq.heappushpop(nums, tmp)
#         return count
#
#
# a = Solution().halveArray([3, 8, 20])
# print(a)
# print(hex(255))
# def move(x, y) -> tuple:
#     return x, y
#
#
# ret = move(1, 2)
# print(type(ret))
# def quadratic(a, b, c):
#     return (-b + (b ** 2 - 4 * a * c) ** 0.5) / (2 * a), \
#         (-b - (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)
#
#
# print(quadratic(1, 3, 2))
# def calc(*num):
#     my_sum = 0
#     for n in num:
#         my_sum += n
#     return my_sum
#
#
# print(calc(range(1,101)))
# def person(name, age, **kw):
#     if "city" in kw:
#         pass
#     if "job" in kw:
#         print(name, "-", age, "-others: ", kw)
#
#
# print(person("王有东", 20, job="程序员"))
# def person(name, age, *, kw):
#     if "city" in kw:
#         pass
#     if "job" in kw:
#         print(name, "-", age, "-others: ", kw)
#
#
# print(person("王有东", 20, job="程序员"))
# s = '     '
# print(s.isspace())
# s = "abcd"
# print(s.replace("ab", "sssaac"))
# a = abs;
# print(a(-1))
# def add(a, b=20) -> int:
#     b = 10
#     return a + b
#
#
# print(add(10, 30))
# def add_end(L=[]) -> list:
#     L.append('end')
#     return L
#
#
# print(add_end())
# print(add_end())
# print(add_end())
# def add(a=b):
#     return a
#
#
# print(add())
# print(add())
# print(add())
# def fun(*num):
# return num


# nums = [1,2,3]
# print(fun(*nums))
# print(fun(*range(1, 100)))

# l = [1, 2, 3, 4, 5]
# print(l[:400])
# for i,j in [(1,2),(3,4),(5,6)]:
#     print(i)
#     print(j)
# print([x * x for x in range(1, 10)])
# L1 = ['Hello', 'World', 18, 'Apple', None]
# L2 = [l.lower() for l in L1  if isinstance(l, str)]
# print(L2)
import datetime
from collections.abc import Iterable
import sys
from typing import Tuple, Iterator


#
# double = 12_34.21
# print(double)
# h = 0x1234
# print(h)
# e = 0o12345
# print(e)
# c = 1.23 * 10 ** 8
# print(c)
# d = 1.23 * 10 ** (-3)
# print(d)
# e = 'sa'
# print(e)
# f = "sasasa"
# print(f)
# g = "我的名字是'Tree'"
# print(g)
# h = '''他说："他的名字是 'hello'"'''
# print(h)
# i = '他说："sasa"'
# print(i)
# j = r"sasasa\t\t\t\t"
# print(j)
# j = '''line1
# ...line2'''
# print(j)
# j = ("line1"
#      "...line2")
# print(j)
# j = True
# print(sys.getsizeof("1234567"))
# if (1):
#     print("true")
# if (-1):
#     print("true")
# if (not 0):
#     print("false")
# if None:
#     print("true")
# else:
#     print("flase")
# print(None)
# a = "hello"
# print(len(a))
# print("this is %d %s\n" % (23, '444dascs'))
# print("你好啊，我的名字是{0:5s}，我今年{1:03d}\n".format('王有东', 20))
# a = 20
# b = "wyd"
# print(f"my name is {b}, I am {a}")
# classmates = ['wyd', 'jxy', 2, 3.14]
# print(classmates[-5])
# py_list = [1, 'hello', 3.14, [1, 2, 3], (2, 3, 4)]
# print(py_list)
# py_list = list([1, 'hello', 3.14])
# print(py_list)
# arr1 = [1, 2, 3]
# arr2 = [4, 5, 6]
# arr1.insert(0, arr2)
# print(arr1)
# print(arr1 + arr2)
# print(arr1)
# arr1.extend(arr2)
# print(arr1)

# tuple1 = (1,)
# print(tuple1
#
# tuple2 = (2)
# print(tuple2)
# tuple1 = (1, 2.3, ['hello', 666, 7])
# print(tuple1)
# tuple1[-1][0] = 'sa'
# print(tuple1)
# for i in range(1, 100, 2):
#     print(i)
# d = {888: 2, 'wyd': 4}
# if 2 in d:
#     if 222 not in d:
#         print('ssss')
# print(d[888])
# s = {1, 2, 3, (4, 5, 6), (7, [8, 9])}
# print(s)
# s = {1, 2, 3}
# print(s)
# print(2 ** -1)
# print(232 % 14)
# if 1 < 2 < 4 < 5 < 6 :
#     print('sasas')
# print(1 is 1)
# a = 1
# print(a ^ 2)
# a = 10
# b = 10
# if a is b:
#     print("Sas")
# PI = 10
# PI = '21e21e'
# print(PI)
# a = 10
# b = 10
# print(id(a))
# print(id(b))
# a = 10
# def fun():
#     global a
#     a = 30
#     print(a)
#
#
# print(fun())
#
# def fun():
#     a = 20
# def fun2():
#     a = 30
# print(a)
# fun2()
# print(a)
#
#
# fun()
# a = (1, 2, 3)
# b = (1, 2, 3)
# print(id(a))
# print(id(b))
# print(a)
# print(b)
# def func(a, b):
# return a + b
# print(func('sasa', 'sxxxx'))


# def func():
#     pass
# def func() -> tuple[int, int, int, int, str, float]:
#     return 1, 2, 3, 4, '222', 3.41
#
#
# a = func()
# print(a)
# def func(arr=None):
#     if arr is None:
#         arr = []
#         arr.append('Hello')
#         print("id = %d" % (id(arr)))
#         print(arr)
#
#
# func()
# func()
# func()


# def func(*num):
#     s = 0
#     for i in num:
#         s += i
#     return s
#
#
# ret = func(1, 2, 3, 4, 5, 6, 7, 8)
# print(ret)
# def func(name, age, **kw):
#     print('name:', name, '\nage:', age, '\nothers:', kw)
#
#
# dic = {'city': '上海', 'work': '程序员'}
# func('yy', 18, **dic)
# func(name='www', age=)
# def func(id_num, name='dd', age=20):
#     print('id:', id_num, '\nname:', name, '\nage:', age)
#
#
# func(1, age=18)
# def fun(name, age, *, city, work):
#     print('name:', name, '\nage:', age, '\ncity:', city, '\nwork', work)
#
#
# fun('wyd', 20, city='上海', work='程序员')
# def fact(n):
#     if n == 1:
#         return n
#     return n * fact(n - 1)


# def fact_operator(n, s):
#     if n == 1:
#         return s
#     return fact_operator(n - 1, n * s)
#
#
# def fact(n):
#     return fact_operator(n, 1)
#
#
# # 让s来计算阶乘
#
#
# print(fact(999))

# lis = [1, 2, 3, 4, 5, 6]
# d = {1: 2, 3: 4}
# # print(lis[0:3])
# # print(d[0:3])
# print(lis[2:-1])

# def trim(s):
#     if s == '':
#         return ''
#
#     pos = 0
#     while s[pos] == ' ':
#         pos += 1
#         if pos == len(s):
#             return ''
#     begin = pos
#     pos = -1
#     while s[pos] == ' ':
#         pos -= 1
#     end = pos
#     if end == -1:
#         return s[begin:]
#     return s[begin:end + 1]
#
#
# if trim('hello  ') != 'hello':
#     print('测试失败!')
# elif trim('  hello') != 'hello':
#     print('测试失败!')
# elif trim('  hello  ') != 'hello':
#     print('测试失败!')
# elif trim('  hello  world  ') != 'hello  world':
#     print('测试失败!')
# elif trim('') != '':
#     print('测试失败!')
# elif trim('    ') != '':
#     print('测试失败!')
# else:
#     print('测试成功!')
# s = "sasas"
# print(isinstance(s, Iterable))
# for x, y, z in [(1, 2, 3), (3, 4, 5), (5, 6, 7)]:
#     print(x, y, z)
# 请使用迭代查找一个list中最小和最大值，并返回一个tuple：
# def findMinAndMax(lis):
#     if lis == []:
#         return None, None
#     max_num = min_num = lis[0]
#     for i in lis:
#         if max_num < i:
#             max_num = i
#         if min_num > i:
#             min_num = i
#     return min_num, max_num
#
#
# if findMinAndMax([]) != (None, None):
#     print('测试失败! 1')
# elif findMinAndMax([7]) != (7, 7):
#     print('测试失败! 2')
# elif findMinAndMax([7, 1]) != (1, 7):
#     print('测试失败! 3')
# elif findMinAndMax([7, 1, 3, 9, 5]) != (1, 9):
#     print('测试失败! 4')
# else:
#     print('测试成功!')
# lister = list(range(1, 11))

# tupler = tuple(range(1, 11))
# print(tupler)
# dic = dict({list(range(1, 11)): list(range(12, 22))})
# print(dic)
# for i in range(1, 11, 2):
#     print(i)
# lister = list(range(1, 11))
# lister = [i for i in range(3, 9)]
#
# tupler = tuple(range(2, 10))
# lis = [x + y for x in 'ABC' for y in 'XYZ']
# print(lis)
# lis = [i if i % 2 == 0 else -i for i in range(1, 11)]
# print(lis)
# def obs():
#     yield (i for i in range(1, 11))
#     yield (i for i in 'asbcd')
#
#
# for a in obs():
#     for b in a:
#         print(b)
# lis = (i for i in range(1, 22))
# print(next(lis))
# print(next(lis))
# print(next(lis))
# print(next(lis))
# print(next(lis))
# print(next(lis))
# print(isinstance([1, 2, 3], Iterator))
# print(isinstance((1, 2, 3), Iterator))
# print(isinstance({1: 2, 2: 3}, Iterator))
# print(isinstance({1, 2, 3}, Iterator))
# print(isinstance('wyd', Iterator))
# print(isinstance((i for i in 'wyd'), Iterator))
# print(isinstance(range(1, 2), Iterator))
# isinstance(l, Iterator)
# lis = [1, 2, 3]
#
# print(isinstance(iter(lis), Iterator))
# print(type(iter(lis)))
# print(type(lis))
# print(isinstance(lis, Iterable))
# my_abs = abs;
# print(my_abs(-10))
# def add(a, b):
#     return a + b
#
#
# my_add = add;
# print(my_add(1, 2))
# print(my_add('abc', 'ABC'))
# 利用map()函数，把用户输入的不规范的英文名字，变为首字母大写， 其他小写的规范名字。
# 输入：['adam', 'LISA', 'barT']，输出：['Adam', 'Lisa', 'Bart']：

# def normalize(name):
# def lazy_sum(num):
#     def quick_sum():
#         i = 1
#         all_num = 0
#         while i <= num:
#             all_num += i
#             i += 1
#         return all_num
#
#     return quick_sum
#
#
# total = lazy_sum(100)  # 返回一个求和函数，不会直接求和
# t = total()            # 在调用该求和函数的时候才会求和
# # print(t)
# def first():
#     lister = []
#     for i in range(1, 4):
#         def second():
#             return i
#         lister.append(i)
#     return lister

# def first_func():
#     lister = []
#     for i in range(1, 4):
#         def second_func():
#             lister.append(i)
#             return lister
#     return second_func
#
#
# x = first_func()
# y = first_func()
# z = first_func()
# print(x())
# print(y())
# print(z())

# my_sum = lambda x, y: x + y
# print(my_sum)
# print(my_sum(3, 5))
# def add(x, y):
#     return x + y
#
#
# my_sum = add
# print(my_sum(3, 5))
# def function(x):
#     """This is a sample function"""
#     return x + 1
#
# print(function.__name__)
# print(function.__doc__)
# import functools
#
# int2 = functools.partial(int, base=2)  # 创建一个专门用于二进制序列转换为十进制的函数
# print(int2('111'))
# print(int2('1234', base=10))  # 仍然可以传参
# def _func():
# class Student(object):
#     def __init__(self, name, age):  # 参数与普通函数的参数设定形式一致，只不过类方法都多了self
#         self.__name = name
#         self.__age = age
#
#     def __print_student(self):
#         print("%s %d" % (self.__name, self.__age))
#
# s = Student('dd', 20)
# print(s.__age) #不允许访问
# s.__print_student() # 不允许访问
# class Animal(object):
#     name = '小丁'
#     def Run(self):
#         print('Animal is running ~ ')
#
#
# # class Dog(Animal):
# #     def Run(self):
# #         print('Dgo is running ~')
#
#
# a1 = Animal()
# print(a1.name)
#
# a2 = Animal()
# print(a2.name)
# class Student(object):
#     def __init__(self, name):  # 设置名字属性
#         self.name = name
#
#
# s = Student('Bob')
# s.score = 90  # 添加成绩属性

# from types import MethodType


# class Student(object):
#     name = 'Bob'
#
#     def change_name(self, name):
#         self.name = name
#
#
# def printf(self):
#     print("%s的成绩是%d" % (self.name, self.score))
#
#
# s = Student()
# s.printf = MethodType(printf, s)  # 给实例化对象绑定一个成员方法
# s.score = 90  # 添加成员变量
# s.printf()
# class Student(object):
#     name = 'Bob'
#
#     def change_name(self, name):
#         self.name = name
#
#
# s1 = Student()
# s2 = Student()
# print(s1.name)
# s1.change_name('Jody')
# print(s1.name)
# print(s2.name)
# class Student(object):
#     __slots__ = ('name', 'age')  # 限制Student类只允许有name和age两个属性
#
#     def __init__(self, name, age):
#         self.name = name
#         self.age = age
#
#     def printf(self):
#         print("%s is %d" % (self.name, self.age))
#
#
# s = Student('dd', 20)
# s.printf()
# class Student(object):
#     __slots__ = ('name', 'age')  # 限制Student类只允许有name和age两个属性
#
#     def __init__(self, name, age):
#         self.name = name
#         self.age = age
#
#     def printf(self):
#         print("%s is %d" % (self.name, self.age))
#
#
# class Bob(Student):
#     pass
#
#
# b = Bob('Bob', 20)
# Bob.score = 90  # 不限制派生类的实例化对象的实例属性添加
# print(Bob.score)
# class Student(object):
#     def __init__(self, name, age, score):
#         self.name = name
#         self.age = age
#         self.__score = score
#
#     @property # 读属性
#     def score(self):
#         return self.__score
#
#     @score.setter # 写属性
#     def score(self, score):
#         if not isinstance(score, int):
#             raise ValueError('score must be a integer')
#         if score < 0 or score > 100:
#             raise ValueError('socre must be in [0, 100]')
#         self.__score = score
#
#
# s = Student('dd', 20, 80)
# s.score = 60
# print(s.score)
# 添加一个输出日志的功能
# def log(func):
#     def wrapper(*args):
#         print('call %s()' % func.__name__)
#         return func(*args)
#
#     return wrapper
#
#
# @log
# def student(name, age, score):
#     print("name = %s, age = %d, score = %.2f," % (name, age, score))
#
#
# student('dd', 20, 100)































